//
//  UITextField+ColorFont.m
//  WoComCloud
//
//  Created by xhkj on 2020/1/3.
//  Copyright © 2022 WC. All rights reserved.
//

#import "UITextField+ColorFont.h"


@implementation UITextField (ColorFont)

- (void)setClearButtonImg:(NSString *)img
{
    UIButton *ClearButton = [self valueForKey:@"_clearButton"];//key值是固定的
    [ClearButton setImage:[UIImage imageNamed:img] forState:UIControlStateNormal];
}

- (void)setPlaceholderColor:(UIColor *)color font:(UIFont *)font
{
    if (@available(iOS 13.0, *)) {
        NSDictionary *dic = @{NSForegroundColorAttributeName:color?color:self.textColor,
                              NSFontAttributeName:font?font:self.font
                            };
        
        NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:self.placeholder ? self.placeholder : @"" attributes:dic];

        self.attributedPlaceholder = attrString;
    }else{
        [self setValue:color forKeyPath:@"_placeholderLabel.textColor"];
        [self setValue:font forKeyPath:@"_placeholderLabel.font"];

    }
}



@end

